Skip to content

Comments

feat: feat: add to_time, to_local_time, to_date functions#1387

Open
mesejo wants to merge 1 commit intoapache:mainfrom
mesejo:feat/expose_to_time_function
Open

feat: feat: add to_time, to_local_time, to_date functions#1387
mesejo wants to merge 1 commit intoapache:mainfrom
mesejo:feat/expose_to_time_function

Conversation

@mesejo
Copy link
Contributor

@mesejo mesejo commented Feb 19, 2026

Which issue does this PR close?

N/A

Rationale for this change

Expose missing temporal functions

What changes are included in this PR?

The functions to_time, to_local_time, to_date, and the corresponding tests.

Fix conditional on to_timestamp since it is args it can not be None, see:

def foo(*args):
    print(args)

foo()

Output
()

Add the alias today for the current_date function

Are there any user-facing changes?

Yes, new functions were added

@mesejo mesejo force-pushed the feat/expose_to_time_function branch 2 times, most recently from 1297aae to 5c639b5 Compare February 20, 2026 15:44
@mesejo mesejo changed the title feat: add to_time function feat: feat: add to_time, to_local_time, to_date functions Feb 20, 2026
@mesejo mesejo force-pushed the feat/expose_to_time_function branch 3 times, most recently from 18b3258 to 2c76187 Compare February 21, 2026 15:31
Additionally fix conditional on formatters (since it is *args it cannot be None)
Refactor name to avoid possible collision with f.
@mesejo mesejo force-pushed the feat/expose_to_time_function branch from 2c76187 to a8d1166 Compare February 21, 2026 16:17
Copy link
Contributor

@kosiew kosiew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mesejo for working on this/

Comment on lines +1040 to +1041
formatters = [fmt.expr for fmt in formatters]
return Expr(f.to_date(arg.expr, *formatters))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_date, to_time, and to_timestamp* each perform the same formatter-unwrapping ([fmt.expr for fmt in formatters]) and “no formatters” branching.
What do you think of extracting a tiny private helper (e.g. _unwrap_exprs(*args: Expr) -> list[PyExpr]) and/or a shared optional-format dispatch helper to reduce duplication and keep behavior aligned across functions?

return Expr(f.now())


def to_char(arg: Expr, format: Expr) -> Expr:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format shadows Python’s built-in format.
What do you think of renaming to formatter like in to_date?

);
expr_fn!(now);
expr_fn_vec!(to_date);
expr_fn_vec!(to_local_time);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_local_time is exposed in Python as unary (def to_local_time(arg: Expr)).
Why do we need expr_fn_vec! here?

If expr_fn_vec! is intentionally required by upstream API shape, a short comment here would prevent future confusion.

return Expr(f.current_date())


today = current_date
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This alias appears unrelated to the PR and is not added to __all__ or covered by tests/docs.

"02-07-2020",
],
type=pa.string(),
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good positive-path coverage was added to test_temporal_functions

Consider adding some focused negative-case assertion for invalid formatter/input for the new API (e.g. malformed to_time formatter), to ensure error surfaces are stable and user-facing diagnostics remain clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants